﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfApplication1.tools
{
    public class cLine
    {
        public Point currentPoint = new Point();
        public Line line = null;
        public bool selected = false;
        public Color brushColor;
        public int brushThickness = 1;

        public void MouseDown(Point newPosition)
        {
            currentPoint = newPosition;
        }

        public void MouseUp()
        {
                line = null;
        }

        public void MouseMove(Point newPosition, Canvas canvas1)
        {
            if (selected)
            {
                if (line == null)
                {
                    line = new Line();
                    line.MouseDown += new MouseButtonEventHandler(line_MouseDown);
                    line.Stroke = new SolidColorBrush(brushColor);
                    line.StrokeThickness = brushThickness;
                    line.X1 = currentPoint.X;
                    line.Y1 = currentPoint.Y;
                    line.X2 = newPosition.X;
                    line.Y2 = newPosition.Y;
                    canvas1.Children.Add(line);
                }
                else
                {
                    line = (Line)canvas1.Children[canvas1.Children.Count - 1];
                    line.X2 = newPosition.X;
                    line.Y2 = newPosition.Y;
                }
            }
        }

        void line_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ((Line)sender).Stroke = new SolidColorBrush(Colors.Green);
        }
    }
}
